<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 性感周周
  Date: 2021/11/29
  Time: 9:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/fileupload.js"></script>
    <script src="bootstrap-4.6.0-dist/js/bootstrap.min.js"></script>
    <script src="My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" href="bootstrap-4.6.0-dist/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-sm-2">
           <jsp:include page="/layout/left.jsp"></jsp:include>
        </div>
        <div class="col-sm-10">
            <form action="addan.do" method="post">
                产品编号: <input type="text" readonly name="cpbh" id="cpbh"  value="${param.snowid!=''?param.snowid:snowid}">
                发布时间: <input type="text" name="createdate"> <br>
                品牌: <input type="text" name="name">
                品类: <input type="text" name="leibie"> <br>
                主版本号: <input type="text" name="typez">
                从版本号: <input type="text" name="typec"> <br>
                制图文件: <input type="text" name="pic">
                总用量: <input type="text" name="ddnums"  readonly id="ddnums"> <br>
                制作人:
                <select name="zzname" id="zzname">
                    <option value="">请选择</option>
                    <option value="root">root</option>
                    <option value="admin">admin</option>
                    <option value="zzy">zzy</option>
                </select>

                审核人:
                <select name="shenhe" id="shenhe">
                    <option value="">请选择</option>
                    <option value="root">root</option>
                    <option value="admin">admin</option>
                    <option value="zzy">zzy</option>
                </select><br>
                <input type="submit" value="添加">
            </form>
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
                添加物料
            </button>
            <table class="table table-hover table-bordered table-primary" id="ta">
                <tr>
                    <td>生产阶段</td>
                    <td>层级</td>
                    <td>物料编号</td>
                    <td>物料名称</td>
                    <td>型号规格</td>
                    <td>单位</td>
                    <td>用量</td>
                    <td>位置</td>
                    <td>备注</td>
                    <td>操作</td>
                </tr>
            </table>
            <!-- Button trigger modal -->


            <!-- Modal -->
            <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <form action="addwl.do" method="post">
                                物料编号:<input type="text" readonly name="wuliao" readonly id="wuliao" value="${param.snowid!=''?param.snowid:snowid}"> <br>
                                生产阶段:<input type="text" name="scjd"> <br>
                                层级:<input type="text" name="cengji"> <br>
                                物料名称:<input type="text" name="wuliaoname"> <br>
                                型号规格:<input type="text" name="xinghao"> <br>
                                单位:<input type="text" name="danwei"> <br>
                                用量:<input type="text" name="num"> <br>
                                位置:<input type="text" name="weizhi"> <br>
                                备注:<input type="text" name="beizhu"> <br>
                                <input type="submit" value="添加"> <br>
                            </form>
                        </div>
                        <%--<div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <button type="button" class="btn btn-primary">Save changes</button>
                        </div>--%>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $(function () {
        if($("#cpbh").val()==""){
            $.post(
                "getsnowid.do",
                function (a) {
                    $("#cpbh").val(a);
                    $("#wuliao").val(a);
                }
            )
        }
        $.post(
            "findallwl.do",
            {"wuliao":$("#wuliao").val()},
            function (a) {
                console.log(a);
                for (let i in a) {
                    $("#ta").append(
                        "<tr>" +
                        "                    <td>"+a[i].scjd+"</td>" +
                        "                    <td>"+a[i].cengji+"</td>" +
                        "                    <td>"+a[i].wuliao+"</td>" +
                        "                    <td>"+a[i].wuliaoname+"</td>" +
                        "                    <td>"+a[i].xinghao+"</td>" +
                        "                    <td>"+a[i].danwei+"</td>" +
                        "                    <td>"+a[i].num+"</td>" +
                        "                    <td>"+a[i].weizhi+"</td>" +
                        "                    <td>"+a[i].beizhu+"</td>" +
                        "                    <td><a href='delwl.do?wuliao="+a[i].wuliao+"&wuliaoname="+a[i].wuliaoname+"'>删除</a></td>" +
                        "                </tr>"
                    )
                }
            }
        )
        var sum=0;
        $.post(
            "findallwl.do",
            {"wuliao":$("#wuliao").val()},
            function (a) {
                for (let i in a) {
                    sum+=a[i].num;
                }
                $("#ddnums").val(sum)
            }
        )
    })
</script>
</html>
